#lang racket
(require "rename-mutable-pair-ops.rkt")

(define (cycled? l)
  (define (check-pair x pair count max-count)
    (cond ((not (pair? x)) false)
          ((eq? x pair) true)
          ((= count max-count) (check-pair (cdr x) x 0 (+ max-count 1)))
          (else (check-pair (cdr x) pair (+ count 1) max-count))))
  (check-pair l '() 0 1))

;(define (cycled? l)
;  (define pair '())
;  (define count 0)
;  (define max-count 1)
;  (define (check-pair x)
;    (cond ((not (pair? x)) false)
;          ((eq? x pair) true)
;          ((= count max-count) (begin (set! pair x)
;                                      (set! count 0)
;                                      (set! max-count (+ max-count 1))
;                                      (check-pair (cdr x))))
;          (else (begin (set! count (+ count 1))
;                       (check-pair (cdr x))))))
;  (check-pair l))



(define last (cons 'l '()))

(define l (cons 'a (cons 'b last)))

(set-cdr! last l)

(cycled? l)

(cycled? (list 'a 'b 'c))

;(print-list l)